// $ANTLR 3.4 src/vb/week4/decluse/Decluse.g 2012-05-29 10:37:02

package vb.week4.decluse;


import org.antlr.runtime.*;
import java.util.Stack;
import java.util.List;
import java.util.ArrayList;

import org.antlr.runtime.tree.*;


@SuppressWarnings({"all", "warnings", "unchecked"})
public class DecluseParser extends Parser {
    public static final String[] tokenNames = new String[] {
        "<invalid>", "<EOR>", "<DOWN>", "<UP>", "DECLARATION", "DIGIT", "ID", "LETTER", "LOWER", "LPAREN", "PROGRAM", "RPAREN", "UPPER", "USE", "WS"
    };

    public static final int EOF=-1;
    public static final int DECLARATION=4;
    public static final int DIGIT=5;
    public static final int ID=6;
    public static final int LETTER=7;
    public static final int LOWER=8;
    public static final int LPAREN=9;
    public static final int PROGRAM=10;
    public static final int RPAREN=11;
    public static final int UPPER=12;
    public static final int USE=13;
    public static final int WS=14;

    // delegates
    public Parser[] getDelegates() {
        return new Parser[] {};
    }

    // delegators


    public DecluseParser(TokenStream input) {
        this(input, new RecognizerSharedState());
    }
    public DecluseParser(TokenStream input, RecognizerSharedState state) {
        super(input, state);
    }

protected TreeAdaptor adaptor = new CommonTreeAdaptor();

public void setTreeAdaptor(TreeAdaptor adaptor) {
    this.adaptor = adaptor;
}
public TreeAdaptor getTreeAdaptor() {
    return adaptor;
}
    public String[] getTokenNames() { return DecluseParser.tokenNames; }
    public String getGrammarFileName() { return "src/vb/week4/decluse/Decluse.g"; }


    public static class program_return extends ParserRuleReturnScope {
        Object tree;
        public Object getTree() { return tree; }
    };


    // $ANTLR start "program"
    // src/vb/week4/decluse/Decluse.g:27:1: program : decluse EOF -> ^( PROGRAM decluse ) ;
    public final DecluseParser.program_return program() throws RecognitionException {
        DecluseParser.program_return retval = new DecluseParser.program_return();
        retval.start = input.LT(1);


        Object root_0 = null;

        Token EOF2=null;
        DecluseParser.decluse_return decluse1 =null;


        Object EOF2_tree=null;
        RewriteRuleTokenStream stream_EOF=new RewriteRuleTokenStream(adaptor,"token EOF");
        RewriteRuleSubtreeStream stream_decluse=new RewriteRuleSubtreeStream(adaptor,"rule decluse");
        try {
            // src/vb/week4/decluse/Decluse.g:28:5: ( decluse EOF -> ^( PROGRAM decluse ) )
            // src/vb/week4/decluse/Decluse.g:28:9: decluse EOF
            {
            pushFollow(FOLLOW_decluse_in_program263);
            decluse1=decluse();

            state._fsp--;

            stream_decluse.add(decluse1.getTree());

            EOF2=(Token)match(input,EOF,FOLLOW_EOF_in_program265);  
            stream_EOF.add(EOF2);


            // AST REWRITE
            // elements: decluse
            // token labels: 
            // rule labels: retval
            // token list labels: 
            // rule list labels: 
            // wildcard labels: 
            retval.tree = root_0;
            RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null);

            root_0 = (Object)adaptor.nil();
            // 29:13: -> ^( PROGRAM decluse )
            {
                // src/vb/week4/decluse/Decluse.g:29:17: ^( PROGRAM decluse )
                {
                Object root_1 = (Object)adaptor.nil();
                root_1 = (Object)adaptor.becomeRoot(
                (Object)adaptor.create(PROGRAM, "PROGRAM")
                , root_1);

                adaptor.addChild(root_1, stream_decluse.nextTree());

                adaptor.addChild(root_0, root_1);
                }

            }


            retval.tree = root_0;

            }

            retval.stop = input.LT(-1);


            retval.tree = (Object)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }

        finally {
        	// do for sure before leaving
        }
        return retval;
    }
    // $ANTLR end "program"


    public static class decluse_return extends ParserRuleReturnScope {
        Object tree;
        public Object getTree() { return tree; }
    };


    // $ANTLR start "decluse"
    // src/vb/week4/decluse/Decluse.g:32:1: decluse : LPAREN ! serie RPAREN !;
    public final DecluseParser.decluse_return decluse() throws RecognitionException {
        DecluseParser.decluse_return retval = new DecluseParser.decluse_return();
        retval.start = input.LT(1);


        Object root_0 = null;

        Token LPAREN3=null;
        Token RPAREN5=null;
        DecluseParser.serie_return serie4 =null;


        Object LPAREN3_tree=null;
        Object RPAREN5_tree=null;

        try {
            // src/vb/week4/decluse/Decluse.g:33:5: ( LPAREN ! serie RPAREN !)
            // src/vb/week4/decluse/Decluse.g:33:9: LPAREN ! serie RPAREN !
            {
            root_0 = (Object)adaptor.nil();


            LPAREN3=(Token)match(input,LPAREN,FOLLOW_LPAREN_in_decluse305); 

            pushFollow(FOLLOW_serie_in_decluse308);
            serie4=serie();

            state._fsp--;

            adaptor.addChild(root_0, serie4.getTree());

            RPAREN5=(Token)match(input,RPAREN,FOLLOW_RPAREN_in_decluse310); 

            }

            retval.stop = input.LT(-1);


            retval.tree = (Object)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }

        finally {
        	// do for sure before leaving
        }
        return retval;
    }
    // $ANTLR end "decluse"


    public static class serie_return extends ParserRuleReturnScope {
        Object tree;
        public Object getTree() { return tree; }
    };


    // $ANTLR start "serie"
    // src/vb/week4/decluse/Decluse.g:36:1: serie : ( unit )* ;
    public final DecluseParser.serie_return serie() throws RecognitionException {
        DecluseParser.serie_return retval = new DecluseParser.serie_return();
        retval.start = input.LT(1);


        Object root_0 = null;

        DecluseParser.unit_return unit6 =null;



        try {
            // src/vb/week4/decluse/Decluse.g:37:5: ( ( unit )* )
            // src/vb/week4/decluse/Decluse.g:37:9: ( unit )*
            {
            root_0 = (Object)adaptor.nil();


            // src/vb/week4/decluse/Decluse.g:37:9: ( unit )*
            loop1:
            do {
                int alt1=2;
                int LA1_0 = input.LA(1);

                if ( (LA1_0==DECLARATION||LA1_0==LPAREN||LA1_0==USE) ) {
                    alt1=1;
                }


                switch (alt1) {
            	case 1 :
            	    // src/vb/week4/decluse/Decluse.g:37:10: unit
            	    {
            	    pushFollow(FOLLOW_unit_in_serie331);
            	    unit6=unit();

            	    state._fsp--;

            	    adaptor.addChild(root_0, unit6.getTree());

            	    }
            	    break;

            	default :
            	    break loop1;
                }
            } while (true);


            }

            retval.stop = input.LT(-1);


            retval.tree = (Object)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }

        finally {
        	// do for sure before leaving
        }
        return retval;
    }
    // $ANTLR end "serie"


    public static class unit_return extends ParserRuleReturnScope {
        Object tree;
        public Object getTree() { return tree; }
    };


    // $ANTLR start "unit"
    // src/vb/week4/decluse/Decluse.g:40:1: unit : ( DECLARATION ^ ID | USE ^ ID | LPAREN ! serie RPAREN !);
    public final DecluseParser.unit_return unit() throws RecognitionException {
        DecluseParser.unit_return retval = new DecluseParser.unit_return();
        retval.start = input.LT(1);


        Object root_0 = null;

        Token DECLARATION7=null;
        Token ID8=null;
        Token USE9=null;
        Token ID10=null;
        Token LPAREN11=null;
        Token RPAREN13=null;
        DecluseParser.serie_return serie12 =null;


        Object DECLARATION7_tree=null;
        Object ID8_tree=null;
        Object USE9_tree=null;
        Object ID10_tree=null;
        Object LPAREN11_tree=null;
        Object RPAREN13_tree=null;

        try {
            // src/vb/week4/decluse/Decluse.g:41:5: ( DECLARATION ^ ID | USE ^ ID | LPAREN ! serie RPAREN !)
            int alt2=3;
            switch ( input.LA(1) ) {
            case DECLARATION:
                {
                alt2=1;
                }
                break;
            case USE:
                {
                alt2=2;
                }
                break;
            case LPAREN:
                {
                alt2=3;
                }
                break;
            default:
                NoViableAltException nvae =
                    new NoViableAltException("", 2, 0, input);

                throw nvae;

            }

            switch (alt2) {
                case 1 :
                    // src/vb/week4/decluse/Decluse.g:41:9: DECLARATION ^ ID
                    {
                    root_0 = (Object)adaptor.nil();


                    DECLARATION7=(Token)match(input,DECLARATION,FOLLOW_DECLARATION_in_unit356); 
                    DECLARATION7_tree = 
                    (Object)adaptor.create(DECLARATION7)
                    ;
                    root_0 = (Object)adaptor.becomeRoot(DECLARATION7_tree, root_0);


                    ID8=(Token)match(input,ID,FOLLOW_ID_in_unit359); 
                    ID8_tree = 
                    (Object)adaptor.create(ID8)
                    ;
                    adaptor.addChild(root_0, ID8_tree);


                    }
                    break;
                case 2 :
                    // src/vb/week4/decluse/Decluse.g:42:9: USE ^ ID
                    {
                    root_0 = (Object)adaptor.nil();


                    USE9=(Token)match(input,USE,FOLLOW_USE_in_unit369); 
                    USE9_tree = 
                    (Object)adaptor.create(USE9)
                    ;
                    root_0 = (Object)adaptor.becomeRoot(USE9_tree, root_0);


                    ID10=(Token)match(input,ID,FOLLOW_ID_in_unit372); 
                    ID10_tree = 
                    (Object)adaptor.create(ID10)
                    ;
                    adaptor.addChild(root_0, ID10_tree);


                    }
                    break;
                case 3 :
                    // src/vb/week4/decluse/Decluse.g:43:9: LPAREN ! serie RPAREN !
                    {
                    root_0 = (Object)adaptor.nil();


                    LPAREN11=(Token)match(input,LPAREN,FOLLOW_LPAREN_in_unit382); 

                    pushFollow(FOLLOW_serie_in_unit385);
                    serie12=serie();

                    state._fsp--;

                    adaptor.addChild(root_0, serie12.getTree());

                    RPAREN13=(Token)match(input,RPAREN,FOLLOW_RPAREN_in_unit387); 

                    }
                    break;

            }
            retval.stop = input.LT(-1);


            retval.tree = (Object)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }

        finally {
        	// do for sure before leaving
        }
        return retval;
    }
    // $ANTLR end "unit"

    // Delegated rules


 

    public static final BitSet FOLLOW_decluse_in_program263 = new BitSet(new long[]{0x0000000000000000L});
    public static final BitSet FOLLOW_EOF_in_program265 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_LPAREN_in_decluse305 = new BitSet(new long[]{0x0000000000002A10L});
    public static final BitSet FOLLOW_serie_in_decluse308 = new BitSet(new long[]{0x0000000000000800L});
    public static final BitSet FOLLOW_RPAREN_in_decluse310 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_unit_in_serie331 = new BitSet(new long[]{0x0000000000002212L});
    public static final BitSet FOLLOW_DECLARATION_in_unit356 = new BitSet(new long[]{0x0000000000000040L});
    public static final BitSet FOLLOW_ID_in_unit359 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_USE_in_unit369 = new BitSet(new long[]{0x0000000000000040L});
    public static final BitSet FOLLOW_ID_in_unit372 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_LPAREN_in_unit382 = new BitSet(new long[]{0x0000000000002A10L});
    public static final BitSet FOLLOW_serie_in_unit385 = new BitSet(new long[]{0x0000000000000800L});
    public static final BitSet FOLLOW_RPAREN_in_unit387 = new BitSet(new long[]{0x0000000000000002L});

}